package cn.edu.imau.zy.system.controller;

import cn.edu.imau.zy.common.annotation.LoginUser;
import cn.edu.imau.zy.common.core.controller.BaseController;
import cn.edu.imau.zy.common.core.domain.R;
import cn.edu.imau.zy.common.core.entity.system.SysAppBanner;
import cn.edu.imau.zy.common.core.entity.system.SysUser;
import cn.edu.imau.zy.system.service.ISysAppBannerService;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序轮播图 提供者
 * 
 * @author wyz
 * @date 2020-07-09
 */
@RestController
@RequestMapping("banner")
public class SysAppBannerController extends BaseController
{
	
	@Autowired
	private ISysAppBannerService sysAppBannerService;
	
	/**
	 * 查询${tableComment}
	 */
	@GetMapping("get/{id}")
	public SysAppBanner get(@PathVariable("id") String id)
	{
		return sysAppBannerService.selectSysAppBannerById(id);
		
	}
	
	/**
	 * 查询小程序轮播图列表
	 */
	@GetMapping("list")
	public R list(SysAppBanner sysAppBanner)
	{
		startPage();
        return result(sysAppBannerService.selectSysAppBannerList(sysAppBanner));
	}

	/**
	 * 查询小程序轮播图列表
	 */
	@GetMapping("allList")
	public R allList()
	{
		SysAppBanner sysAppBanner = new SysAppBanner();
		sysAppBanner.setOpen(true);
		sysAppBanner.setFileName("1");
		return R.data(sysAppBannerService.selectSysAppBannerList(sysAppBanner));
	}
	
	
	/**
	 * 新增保存小程序轮播图
	 */
	@PostMapping("save")
	public R addSave(@RequestBody SysAppBanner sysAppBanner,@LoginUser SysUser user)
	{
		sysAppBanner.setId(IdUtil.getSnowflake(1,1).nextIdStr());
		sysAppBanner.setCreateBy(user.getUserId().toString());
		return toAjax(sysAppBannerService.insertSysAppBanner(sysAppBanner));
	}

	/**
	 * 修改保存小程序轮播图
	 */
	@PostMapping("update")
	public R editSave(@RequestBody SysAppBanner sysAppBanner,@LoginUser SysUser user)
	{
		sysAppBanner.setUpdateBy(user.getUserId().toString());
		return toAjax(sysAppBannerService.updateSysAppBanner(sysAppBanner));
	}
	
	/**
	 * 删除${tableComment}
	 */
	@PostMapping("remove")
	public R remove(String ids)
	{		
		return toAjax(sysAppBannerService.deleteSysAppBannerByIds(ids));
	}
	
}
